﻿#include <sb.h>

bool isexit = false;

kpointer fn(kpointer ptr)
{
	kint n = K_CAST_PTR_TO_INT(ptr);

	char sz[20];
	sz[k_strfll(sz, 0, 18, n + '0')] = '\0';

	kint cnt = 0;

	while (!isexit)
	{
		k_mesgf("%5d %s\n", cnt++, sz);
		k_sleep(1);
	}

	k_sleep(500);
	k_mesgf("%d -> %d\n", n, cnt);

	return NULL;
}

int main()
{
	k_mesg("THREAD TEST\n");

	kThread* t[10];

	for (int i = 0; i < 10; i++)
	{
		t[i] = k_thread_new(fn, K_CAST_INT_TO_PTR(i), 0, 0);
		k_thread_start(t[i]);
	}

	for (;;)
	{
		int ch = getchar();
		if (ch == 'q')
			break;
	}

	isexit = true;

	for (int i = 0; i < 10; i++)
		k_thread_delete(t[i]);

	return 0;
}
